<template>
	<view>
		<view class="category-list">
			<!-- 左侧分类导航 -->
			<scroll-view scroll-y="true" class="left" style="margin-top: 60upx;">
				<view class="row" v-for="(category, index) in categoryList" :key="category.id"
					:class="[index == showCategoryIndex ? 'on' : '']" @click="showCategory(index)">
					<view class="text">
						<view class="block"></view>
						<view style="width: 80%;text-align: center;">
							{{ category.classifyName }}
						</view>
					</view>
				</view>
			</scroll-view>
			<!-- 右侧子导航 -->
			<scroll-view scroll-y="true" class="right">
				<view class="category" v-for="(category, index) in categoryList" :key="index"
					v-show="index == showCategoryIndex">
					<view style="text-align: center">
						<text style="color: gainsboro">—</text>
						<text
							style="color: #000000;margin-right: 8px;margin-left: 8px">{{ category.classifyName }}</text>
						<text style="color: gainsboro">—</text>
					</view>
					<view class="list" v-if="category.list.length > 0">
						<view class="box" v-for="(box, i) in category.list" :key="i">
							<image @click="select(box,category.classifyName)" :src="box.classifyIcon" lazy-load="true"
								fade-show="true" style="width: 100upx;height: 100upx;border-radius: 50upx;"></image>
							<view class="text">{{ box.classifyDeatilsName }}</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>
<script>
	//高德SDK
	export default {
		data() {
			return {
				showCategoryIndex: 0,
				headerPosition: 'fixed',
				state: '',
				categoryList: []
			};
		},
		onPageScroll(e) {
			//兼容iOS端下拉时顶部漂移
			if (e.scrollTop >= 0) {
				this.headerPosition = 'fixed';
			} else {
				this.headerPosition = 'absolute';
			}
		},
		onLoad(params) {
			this.state = params.state;
			console.log("state: ",this.state);
			this.$queue.showLoading('加载中...');
			this.$Request.getT('/helpClassify/select').then(res => {
				if (res.code === 0) {
					this.categoryList = res.data;
					console.log(JSON.stringify(this.categoryList))
				}
				uni.hideLoading();
			});
		},
		methods: {
			select(item, classifyName) {
				item.remark = item.remark ? item.remark : '';
				if (this.state) {
					this.navToLogin('/package-task/pages/task/tasklist?id=' + item.id + '&state=click');
				} else {
					this.navToLogin('/package-task/pages/task/newTask?id=' + item.id + '&name=' + item.classifyDeatilsName +
						'&classifyName=' +
						classifyName + '&taskZuiDiMoney=' + item.taskMoney + '&taskZuiDiNumber=' + item.taskNum +
						'&remark=' + item.remark
					);
				}
			},
			/**
			 * 统一跳转接口,拦截未登录路由
			 * navigator标签现在默认没有转场动画，所以用view
			 */
			navToLogin(url) {
				let token = this.$queue.getData('token');
				let mobile = this.$queue.getData('mobile');
				let userId = this.$queue.getData('userId');
				if (token) {
					this.$Request.postJson('/app/selectUserById?userId=' + userId).then(res => {
						if (res.code === 0 && res.data.phone) {
							uni.navigateTo({
								url
							});
						} else {
							uni.navigateTo({
								url: '/package-task/pages/public/mobile'
							});
						}
					});
				} else {
					this.goLoginInfo();
				}
			},
			//统一登录跳转
			goLoginInfo() {
				this.$queue.setData('href', '/pages/task/new');
				uni.navigateTo({
					url: '/package-task/pages/public/login'
				});
			},
			//分类切换显示
			showCategory(index) {
				this.showCategoryIndex = index;
			},
			toCategory(name) {
				uni.navigateTo({
					url: '/package-task/pages/categray/search?cid=' + this.showCategoryIndex + '&name=' + name
				});
			}
		}
	};
</script>
<style lang="scss">
	.status {
		width: 100%;
		height: 0;
		position: fixed;
		z-index: 10;
		background-color: #fff;
		top: 0;
		/*  #ifdef  APP-PLUS  */
		height: var(--status-bar-height); //覆盖样式
		/*  #endif  */
	}

	.header {
		width: 92%;
		padding: 0 4%;
		height: 100upx;
		display: flex;
		align-items: center;
		position: fixed;
		top: 0;
		z-index: 10;
		background-color: #fff;
		/*  #ifdef  APP-PLUS  */
		top: var(--status-bar-height);
		/*  #endif  */

		.addr {
			width: 120upx;
			height: 60upx;
			flex-shrink: 0;
			display: flex;
			align-items: center;
			font-size: 28upx;

			.icon {
				height: 60upx;
				margin-right: 5upx;
				display: flex;
				align-items: center;
				font-size: 42upx;
				color: #ffc50a;
			}
		}

		.input-box {
			width: 100%;
			height: 60upx;
			background-color: #f5f5f5;
			border-radius: 30upx;
			position: relative;
			display: flex;
			align-items: center;

			.icon {
				display: flex;
				align-items: center;
				position: absolute;
				top: 0;
				right: 0;
				width: 60upx;
				height: 60upx;
				font-size: 34upx;
				color: #c0c0c0;
			}

			input {
				padding-left: 28upx;
				height: 28upx;
				font-size: 28upx;
			}
		}

		.icon-btn {
			width: 60upx;
			height: 60upx;
			flex-shrink: 0;
			display: flex;

			.icon {
				width: 60upx;
				height: 60upx;
				display: flex;
				justify-content: flex-end;
				align-items: center;
				font-size: 42upx;
			}
		}
	}

	.place {
		background-color: #ffffff;
		height: 100upx;
		/*  #ifdef  APP-PLUS  */
		margin-top: var(--status-bar-height);
		/*  #endif  */
	}

	.category-list {
		width: 100%;
		background-color: #fff;
		display: flex;

		.left,
		.right {
			top: 0upx;
			bottom: 0upx;
		}

		.left {
			position: fixed;
			width: 24%;
			left: 0upx;
			background-color: #f2f2f2;

			.row {
				width: 100%;
				height: 90upx;
				display: flex;
				align-items: center;

				.text {
					width: 100%;
					position: relative;
					font-size: 28upx;
					display: flex;
					justify-content: center;
					color: #3c3c3c;

					.block {
						position: absolute;
						width: 0upx;
						left: 0;
					}
				}

				&.on {
					height: 100upx;
					background-color: #fff;

					.text {
						font-size: 30upx;
						font-weight: 600;
						color: #2d2d2d;

						.block {
							width: 10upx;
							height: 80%;
							top: 10%;
							background-color: #f06c7a;
						}
					}
				}
			}
		}

		.right {
			margin-left: 24%;
			width: 76%;
			left: 24%;

			.category {
				width: 100%;
				padding: 20upx 3%;

				.banner {
					width: 100%;
					height: 24.262vw;
					border-radius: 10upx;
					overflow: hidden;
					box-shadow: 0upx 5upx 20upx rgba(0, 0, 0, 0.3);

					image {
						width: 100%;
						height: 24.262vw;
					}
				}

				.list {
					margin-top: 40upx;
					width: 100%;
					display: flex;
					flex-wrap: wrap;

					.box {
						width: calc(65.44vw / 3);
						margin-bottom: 30upx;
						display: flex;
						margin-left: 15upx;
						justify-content: center;
						align-items: center;
						flex-wrap: wrap;

						image {
							width: 60%;
							height: calc(71.44vw / 3 * 0.6);
						}

						.text {
							margin-top: 5upx;
							width: 100%;
							display: flex;
							justify-content: center;
							font-size: 26upx;
						}
					}
				}
			}
		}
	}
</style>
